<?php
include_once"admin_check.php";

//获得第几页
$page = isset($_GET['page']) && !empty($_GET['page'])?intval($_GET['page']):1;
// 设置每页显示多少条数据
$limit = isset($_GET['limit']) && !empty($_GET['page'])? intval($_GET['limit']):4;

//获得数据表中一共多少条数据
$total = counts('setting');
$total = $total['c'];

// 总数据大于0才显示分页
if($total>0){
  // 显示的页数
  $pageNumber = ceil($total/$limit);
  // offset是指从第几条开始查询
  $offset = ($page -1 )*$limit;
  // 查询分页数据
  $settings = getAll('setting',"1 order by set_id desc limit {$offset},${limit}");

  $pageStr = pagination($total,$page,$limit,$pageNumber,null,'yahoo');
}

if($_GET){

  $id = isset($_GET['idarr']) && !empty($_GET['idarr']) ? $_GET['idarr'] : '';
  if($id){

    if(is_array($id)){
      $did = implode(',', $id);
    }else{
      $did = $id;
    }

    $r = delete('setting',"set_id in ({$did})");

    if($r){
      show_msg('删除成功','website_list.php');
    }else{
      show_msg('删除失败');
    }
  }
}
?>
<?php include_once"header.php" ?>
    <div id="topbar" class="affix">
      <ol class="breadcrumb">
        <li><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
        <li class="active">文章管理</li>
      </ol>
    </div>
    <div class="container">

	 <div class="row">
        <div class="col-md-12">
			<div class="panel">
                <div class="panel-heading">
                  <div class="panel-title">设置列表</div>
                  <a href="website_add_edit.php" class="btn btn-info btn-gradient pull-right"><span class="glyphicons glyphicon-plus"></span> 添加设置</a>
                </div>
                <form action="website_list.php" method="get">
                <div class="panel-body">
                  <table class="table table-striped table-bordered table-hover dataTable">
                      <tr class="active">
                        <th class="text-center">
                          <a class="btn btn-gray btn-sm" id="selectAll">全选</a>
                    <!--       <a class="btn btn-gray btn-sm" id="sltRv">反选</a>
                          <a class="btn btn-gray btn-sm" id="sltDel">取消</a> -->
                        </th>
                        <th>设置ID</th>
                        <th>设置名称</th>
                        <th>设置内容</th>
                        <th width="100">操作</th>
                      </tr>
                      <?php foreach ($settings as $key => $value){ ?>
                        
                    	<tr class="success">
                        <td class="text-center"><input type="checkbox" value="<?php echo $value['set_id']?>" name="idarr[]" class="cbox"></td>
                        <td><?php echo $value['set_id']?></td>
                        <td><?php echo $value['set_name']?></td>
                        <td><?php echo $value['set_value']?></td>
                       
                        <td>
		                      <div class="btn-group">
		                        <a href="website_add_edit.php?eid=<?php echo $value['set_id']?>" class="btn btn-default btn-gradient"><span class="glyphicons glyphicon-pencil"></span></a>
		                        <a onclick="return confirm('确定要删除吗？');" href="website_list.php?idarr=<?php echo $value['set_id']?>" class="btn btn-default btn-gradient dropdown-toggle"><span class="glyphicons glyphicon-trash"></span></a>
		                      </div>
                        </td>
                      </tr>

                      <?php } ?>
                      
                  </table>
                  
                  <div class="pull-left">

                    <button type="submit" onclick="return confirm('确定要删除吗？');" class="btn btn-default btn-gradient pull-right delall"><span class="glyphicons glyphicon-trash"></span></button>



                  </div>
                  
                  <div class="pull-right">
                    <ul class="pagination" id="paginator-example">
                      <?php echo $pageStr?>
                    </ul>
                  </div>
                  
                </div>
                </form>
              </div>
          </div>
        </div>
    </div>
  </section>
  <!-- End: Content --> 
</div>
<!-- End: Main --> 
<script type="text/javascript">
  // 全选
  $('#selectAll').click(function(){
      var love = $('input[name="idarr[]"]');
      $.each(love, function(k,v){
          $(v).prop('checked', true);
      })
  })

  // // 取消 
  $('#sltDel').click(function(){
      var love = $('input[name="idarr[]"]');
      $.each(love, function(k,v){
          $(v).prop('checked', false);
      })
  })
  
  // // 反选
  $('#sltRv').click(function(){
      var love = $('input[name="idarr[]"]');
      $.each(love, function(k,v){
          $(v).prop('checked', !$(v).prop('checked') );
      })
  })
</script>
</body>
</html>